/*
 * Copyright 2014 Christian Hildebrandt.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package de.sisoft.timera.beans;

import java.io.Serializable;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.inject.Inject;

import de.sisoft.timera.entity.Employee;
import de.sisoft.timera.entity.Role;
import de.sisoft.timera.entity.Salutation;
import de.sisoft.timera.service.UserService;

/**
 *
 * @author Christian Hildebrandt
 */
@ManagedBean
@SessionScoped
public class UsersBean implements Serializable {

    private static final long serialVersionUID = -7289992705434088041L;

    private List<Employee> users;
    private Employee editUser = new Employee();
    private Employee deleteUser;
    private boolean editMode = false;

    @Inject
    private UserService userService;

    public List<Employee> getUsers() {
	return userService.getAllUsers();
    }

    public void setUsers(final List<Employee> users) {
	this.users = users;
    }

    public Employee getEditUser() {
	return editUser;
    }

    public void setEditUser(final Employee editUser) {
	this.editUser = editUser;
    }

    public Employee getDeleteUser() {
	return deleteUser;
    }

    public void setDeleteUser(final Employee deleteUser) {
	this.deleteUser = deleteUser;
    }

    public boolean isEditMode() {
	return editMode;
    }

    public void setEditMode(final boolean editMode) {
	this.editMode = editMode;
    }

    public Salutation[] getSalutations() {
	return Salutation.values();
    }

    public Role[] getRoles() {
	return Role.values();
    }

    public String clear() {
	editUser = new Employee();
	setEditMode(false);
	return null;
    }

    public String save() {

	userService.createEmployee(editUser);
	editUser = new Employee();
	setEditMode(false);
	return null;
    }

    public String delete() {
	userService.deleteEmployee(deleteUser);
	return null;
    }

}
